[% setvar title Objects : Rationalizing C<ref>, C<attribute::reftype>, and C<builtin:blessed> %]
<div id="archive-notice">
    <h3>This file is part of the Perl 6 Archive</h3>
    <p>To see what is currently happening visit <a href="http://www.perl6.org/">http://www.perl6.org/</a></p>
</div>
<div class='pod'>
<a name='TITLE'></a><h1>TITLE</h1>
<p>Objects : Rationalizing <code>ref</code>, <code>attribute::reftype</code>, and <code>builtin:blessed</code></p>
<a name='VERSION'></a><h1>VERSION</h1>
<pre>  Maintainer: Damian Conway &lt;<a href='mailto:damian@conway.org'>damian@conway.org</a>&gt;
  Date: 14 Sep 2000
  Last Modified: 18 Sep 2000
  Mailing List: <a href='mailto:perl6-language-objects@perl.org'>perl6-language-objects@perl.org</a>
  Number: 224
  Version: 2
  Status: Frozen</pre>
<a name='ABSTRACT'></a><h1>ABSTRACT</h1>
<p>This RFC proposes that rather than three separate mechanisms (in three
separate namespaces) to determine object typing information, Perl 6
simply extend the <code>ref</code> function to return all the necessary
information in a list context.</p>
<a name='DESCRIPTION'></a><h1>DESCRIPTION</h1>
<p>In Perl 5, the class into which an object is blessed is returned by
calling <code>ref</code> on a reference to that object. To determine the
underlying implementation type of the object, <code>attribute::reftype</code> is
used. To determine whether or not a reference refers to a blessed
object, &lt;builtin::blessed&gt; is used.</p>
<p>It is proposed that the behaviour of <code>ref</code> be altered in Perl 6 so that
in a list context it returns up to two values: the underlying
implementation type of the object (always returned), and the class into
which the object is blessed (only if the object <i>is</i> blessed).</p>
<p>Thus:</p>
<pre>        if (builtin::blessed $ref) {
                $type  = attribute::reftype $ref;
                $class = ref $ref;
        }
        else {
                $type  = ref $ref;
                $class = &quot;&lt;no class&gt;&quot;;
        }

        print &quot;Object of type $type, blessed into $class\n&quot;;</pre>
<p>Would become:</p>
<pre>        ($type, $class) = ref($ref);
        $class ||= &quot;&lt;no class&gt;&quot;;

        print &quot;Object of type $type, blessed into $class\n&quot;;</pre>
<a name='MIGRATION ISSUES'></a><h1>MIGRATION ISSUES</h1>
<p>All existing calls to <code>ref</code> in a list context would have to be
translated to <code>scalar ref</code>.</p>
<a name='IMPLEMENTATION'></a><h1>IMPLEMENTATION</h1>
<p>Trivial.</p>
<a name='REFERENCES'></a><h1>REFERENCES</h1>
<p>None.</p>
</div>
